unity Texture2D efficient performance draw pixels

117

unity Texture2D efficient performance draw pixels -

var pixels = myTexture.GetPixels32();
for (int i = 0; i < pixels.Length; i++) 
{
    pixels[i] = Color.black;
}
    
    // Draw ants
foreach (Ant ant in ants)
{
    for (int i = 0; i < cellSize; i++)
    {
        for (int j = 0; j < cellSize; j++) 
        {
            // TODO: calculate the index of the pixel in the flat array
            // Not 100% sure on that one tbh ;)
            var index = (ant.thisX * cellSize + i) + myTexture.width * (ant.thisY * cellSize + j);
            
            pixels[index] = Color.white
        }
    }
}

myTexture.SetPixels32(pixels);

myTexture.Apply();

Comments

Submit
0 Comments